/*
 * @Date         : 2024-05-17 11:33:45 星期5
 * @Author       : xut
 * @Description  :
 */
import { PrismaClient } from "@prisma/client"

declare global {
  var prisma: PrismaClient | undefined
}

export const prisma = global.prisma || new PrismaClient()

if (process.env.NODE_ENV !== "production") {
  global.prisma = prisma
}

export async function connectDB() {
  try {
    await prisma.$connect()
    console.log("? Database connected successfully")
  } catch (error) {
    console.error(error)
    process.exit(1)
  } finally {
    await prisma.$disconnect()
  }
}
